const { Sequelize } = require("sequelize");

const sequelize = new Sequelize("duyi", "root", "123456", {
  host: "192.168.71.226",
  dialect: "mysql",
  logging: null,
});
//   console.log(sequelize);
const { DataTypes } = require("sequelize");

// 模型操作表
(async function () {
  //   return;

  //创建一个模型对象
  const Admin = sequelize.define(
    "Admin",
    {
      loginId: {
        type: DataTypes.STRING,
        allowNull: false,
      },
      loginPwd: {
        type: DataTypes.STRING,
        allowNull: false,
      },
    },
    {
      //   createdAt: false,
      //   updatedAt: false,
      paranoid: true, //从此以后，该表的数据不会真正的删除，而是增加一列deletedAt，记录删除的时间
    }
  );
  //   console.log("执行了");
  //   let ins = await Admin.findByPk(1);
  //   ins.toJSON();
  //   console.log(ins);
})();

// 班级相关模型
(function () {
  return;
  const Student = sequelize.define(
    "Student",
    {
      name: {
        type: DataTypes.STRING,
        allowNull: false,
      },
      birthdady: {
        type: DataTypes.DATE,
        allowNull: false,
      },
      sex: {
        type: DataTypes.BOOLEAN,
        allowNull: false,
      },
      mobile: {
        type: DataTypes.STRING(11),
        allowNull: false,
      },
    },
    {
      createdAt: false,
      updatedAt: false,
      paranoid: true,
    }
  );
  const Class = sequelize.define(
    "Class",
    {
      name: {
        type: DataTypes.STRING,
        allowNull: false,
      },
      openDate: {
        type: DataTypes.STRING,
        allowNull: false,
      },
    },
    {
      paranoid: true,
    }
  );

  sequelize.sync({ alter: true }).then(() => {
    console.log("所有模型同步完成");
  });
})();
